﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AppSocketModel;
using AppSocketModel.Alarm;
using AppSocketService;
using AppSocketService.Alarm;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BCGPSRESTful.Controllers.Phone.Alarm
{
    /// <summary>
    /// 个人用户手机端报警配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "PersonApp")]
    [Route("api/[controller]")]
    [ApiController]
    public class PhoneAlarmPersonController : PhoneBaseController
    {
        private readonly IAlarmPersonService alarmPersonService;

        #region   构造函数
        /// <summary>
        /// 
        /// </summary>
        /// <param name="alarmPersonService"></param>
        public PhoneAlarmPersonController(IAlarmPersonService alarmPersonService)
        {
            this.alarmPersonService = alarmPersonService;
        }
        #endregion

        //public ActionResult<>

        #region 设置报警配置 (根据IMEI)
        /// <summary>
        /// 设备报警配置 (根据IMEI)
        /// </summary>
        /// <param name="alarmDto"></param> 
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetAlarmConfig([FromBody] AlarmDto alarmDto)
        {
            return alarmPersonService.SetAlarmConfig(alarmDto);
        }
        #endregion

        #region 获取报警配置
        /// <summary>
        /// 获取报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(AlarmDto), 200)]
        [HttpGet("[action]")]
        public ActionResult<AlarmDto> GetAlarmConfig(string imei)
        {
            return alarmPersonService.GetAlarmConfig(imei);
        }
        #endregion

        #region 获取已经配置的报警类型
        /// <summary>
        /// 获取已经配置的报警类型
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(List<AlarmType>), 200)]
        [HttpGet("[action]")]
        public ActionResult<List<AlarmType>> GetAlarmTypes(string imei)
        {
            return alarmPersonService.GetAlarmTypes(imei);
        }
        #endregion

        #region  获取 围栏 报警配置 
        /// <summary>
        /// 获取围栏报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(FenceAlarmDto), 200)]
        [HttpGet("[action]")]
        public ActionResult<FenceAlarmDto> GetFenceAlarmConfig(string imei)
        {
            return (FenceAlarmDto)alarmPersonService.GetAlarmConfigByType(imei, AlarmType.Fence);
        }
        #endregion
          

        #region  获取 位移 报警配置 
        /// <summary>
        /// 获取 位移 警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(MoveAlarmDto), 200)]
        [HttpGet("[action]")]
        public ActionResult<MoveAlarmDto> GetMoveAlarmConfig(string imei)
        {
            return (MoveAlarmDto)alarmPersonService.GetAlarmConfigByType(imei, AlarmType.Move);
        }
        #endregion

        #region  获取 超速 报警配置 
        /// <summary>
        /// 获取 超速 警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(OverSpeedAlarmDto), 200)]
        [HttpGet("[action]")]
        public ActionResult<OverSpeedAlarmDto>GetOverSpeedAlarmConfig(string imei)
        {
            return (OverSpeedAlarmDto) alarmPersonService.GetAlarmConfigByType(imei, AlarmType.OverSpeed);
    }
        #endregion

        #region  获取 防拆 报警配置 
        /// <summary>
        /// 获取 防拆 警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(LightAlarmDto), 200)]
        [HttpGet("[action]")]
        public ActionResult<LightAlarmDto> GetLightAlarmConfig(string imei)
        {
            return (LightAlarmDto)alarmPersonService.GetAlarmConfigByType(imei, AlarmType.Light);
        }
        #endregion

        #region  获取 电池低电压 报警配置 
        /// <summary>
        /// 获取 电池低电压 警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(LowPowerAlarmDto), 200)]
        [HttpGet("[action]")]
        public ActionResult<LowPowerAlarmDto> GetLowPowerAlarmConfig(string imei)
        {
            return (LowPowerAlarmDto)alarmPersonService.GetAlarmConfigByType(imei, AlarmType.LowPower);
        }
        #endregion

        #region 设置 围栏 报警配置
        /// <summary>
        /// 设置 围栏 报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="fenceAlarmDto"> 围栏 报警配置</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetFenceAlarmConfig(string imei, [FromBody] FenceAlarmDto fenceAlarmDto)
        {
            return alarmPersonService.SetAlarmConfigByType(imei, fenceAlarmDto, AlarmType.Fence);
        }
        #endregion

        #region 设置 位移 报警配置
        /// <summary>
        /// 设置 位移 报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="moveAlarmDto">位移 报警配置</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetMoveAlarmConfig(string imei, [FromBody] MoveAlarmDto  moveAlarmDto)
        {
            return alarmPersonService.SetAlarmConfigByType(imei, moveAlarmDto, AlarmType.Move);
        }
        #endregion

        #region 设置 超速 报警配置
        /// <summary>
        /// 设置 超速 报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="overSpeedAlarmDto">超速 报警配置</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetOverSpeedAlarmConfig(string imei, [FromBody] OverSpeedAlarmDto overSpeedAlarmDto  )
        {
            return alarmPersonService.SetAlarmConfigByType(imei, overSpeedAlarmDto, AlarmType.OverSpeed);
        }
        #endregion

        #region 设置 电池低电压 报警配置
        /// <summary>
        /// 设置 电池低电压 报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="lowPowerAlarmDto">电池低电压 报警配置</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetLowPowerAlarmConfig(string imei, [FromBody] LowPowerAlarmDto  lowPowerAlarmDto)
        {
            return alarmPersonService.SetAlarmConfigByType(imei, lowPowerAlarmDto, AlarmType.LowPower);
        }
        #endregion

        #region 设置 防拆 报警配置
        /// <summary>
        /// 设置 防拆 报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="lightAlarmDto">防拆 报警配置</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetLightAlarmConfig(string imei, [FromBody] LightAlarmDto lightAlarmDto  )
        {
            return alarmPersonService.SetAlarmConfigByType(imei, lightAlarmDto, AlarmType.Light);
        }
        #endregion

        #region  设备基础报警配置 (根据IMEI)
        /// <summary>
        /// 设备基础报警配置 (根据IMEI)
        /// </summary>
        /// <param name="imei"></param>
        /// <param name="alarmBaseDto">报警基础配置</param>
        /// <returns></returns>
        [ProducesResponseType(typeof(bool), 200)]
        [HttpPut("[action]")]
        public ActionResult<bool> SetAlarmBaseConfig(string imei, [FromBody] AlarmBaseDto alarmBaseDto)
        {
            return alarmPersonService.SetAlarmBaseConfig(imei,alarmBaseDto);
        }
        #endregion

        #region  删除账户下指定IMEI的报警配置
        /// <summary>
        /// 删除账户下指定IMEI的报警配置
        /// </summary>
        /// <param name="imei"></param>
        /// <returns></returns>
        [ProducesResponseType(typeof(void), 200)]
        [HttpDelete("[action]")]
        public ActionResult Delete(string imei)
        {
            alarmPersonService.Delete(imei);
            return Ok();
        }
        #endregion

        #region  删除账户下的全部报警配置
        /// <summary>
        /// 删除账户下的全部报警配置
        /// </summary>
        /// <returns></returns>
        [ProducesResponseType(typeof(void), 200)]
        [HttpDelete("[action]")]
        public ActionResult DeleteAll()
        {
            alarmPersonService.DeleteAll();
            return Ok();
        }
        #endregion
    }
}